package cn.com.miao.lynx.service.system.mapping;

import cn.com.miao.lynx.common.base.mapping.BaseMapStructMapping;
import cn.com.miao.lynx.common.core.syntactic.OperatorKt;
import cn.com.miao.lynx.common.log.api.LogDetail;
import cn.com.miao.lynx.service.system.entity.SysLog;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * SysLogFromLogDetailMapping
 *
 * @title: SysLogFromLogDetailMapping
 * @description:
 * @author: dengmiao
 * @create: 2019-12-27 13:18
 **/
@Mapper(componentModel = "spring")
public interface SysLogMapping extends BaseMapStructMapping<SysLog, Long> {

    @Override
    default <T> T to(SysLog source, final Class<T> clazz) {
        if (LogDetail.class.equals(clazz)) {
            return (T) toLogDetail(source);
        }
        return null;
    }

    @Override
    default <T> List<T> to(List<SysLog> source, final Class<T> clazz) {
        return OperatorKt.convert(source, sysLog -> to(sysLog, clazz));
    }

    LogDetail toLogDetail(SysLog sysLog);

    List<LogDetail> toLogDetail(List<SysLog> list);

    SysLog fromLogDetail(LogDetail logDetail);

    List<SysLog> fromLogDetail(List<LogDetail> list);
}
